Skip to content

[ASan][cmake] Exclude .so build when building for WASI by default #139042

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented May 8, 2025

libclang_rt.asan.so depends on libc.so and libc++.so but they are not always available and are still not shipped as a part of Swift WebAssembly SDK because it's still in a very early stage. Let's make shared library build optional for now and revisit after #103592 is solved and the shared library will be 1st citizen on WASI

@llvmbot
Copy link
Member

llvmbot commented May 8, 2025

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Yuta Saito (kateinoigakukun)

Changes

libclang_rt.asan.so depends on libc.so and libc++.so but they are not always available
are still not shipped as a part of Swift WebAssembly SDK because it's still in a very early stage. Let's make shared library build optional for now and revisit after #103592 is solved and the shared library will be 1st citizen on WASI


Full diff: https://github.com/llvm/llvm-project/pull/139042.diff

1 Files Affected:

  • (modified) compiler-rt/lib/asan/CMakeLists.txt (+28-19)
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index e2f39f224df9c..5616a40164bd1 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -1,5 +1,12 @@
 # Build for the AddressSanitizer runtime support library.
 
+set(COMPILER_RT_ASAN_BUILD_SHARED_LIBS_default ON)
+if (CMAKE_SYSTEM_NAME STREQUAL "WASI")
+  set(COMPILER_RT_ASAN_BUILD_SHARED_LIBS_default OFF)
+endif()
+option(COMPILER_RT_ASAN_BUILD_SHARED_LIBS
+	"Build AddressSanitizer shared libraries" ${COMPILER_RT_ASAN_BUILD_SHARED_LIBS_default})
+
 set(ASAN_SOURCES
   asan_allocator.cpp
   asan_activation.cpp
@@ -307,25 +314,27 @@ else()
     endif()
 
     set(ASAN_DYNAMIC_WEAK_INTERCEPTION)
-    add_compiler_rt_runtime(clang_rt.asan
-      SHARED
-      ARCHS ${arch}
-      OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
-              RTAsan_dynamic
-              # The only purpose of RTAsan_dynamic_version_script_dummy is to
-              # carry a dependency of the shared runtime on the version script.
-              # Replacing it with a straightforward
-              # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
-              # generates an order-only dependency in ninja.
-              RTAsan_dynamic_version_script_dummy
-              RTUbsan_cxx
-              ${ASAN_DYNAMIC_WEAK_INTERCEPTION}
-      CFLAGS ${ASAN_DYNAMIC_CFLAGS}
-      LINK_FLAGS ${ASAN_DYNAMIC_LINK_FLAGS}
-                ${VERSION_SCRIPT_FLAG}
-      LINK_LIBS ${ASAN_DYNAMIC_LIBS}
-      DEFS ${ASAN_DYNAMIC_DEFINITIONS}
-      PARENT_TARGET asan)
+    if (COMPILER_RT_ASAN_BUILD_SHARED_LIBS)
+      add_compiler_rt_runtime(clang_rt.asan
+        SHARED
+        ARCHS ${arch}
+        OBJECT_LIBS ${ASAN_COMMON_RUNTIME_OBJECT_LIBS}
+                RTAsan_dynamic
+                # The only purpose of RTAsan_dynamic_version_script_dummy is to
+                # carry a dependency of the shared runtime on the version script.
+                # Replacing it with a straightforward
+                # add_dependencies(clang_rt.asan-dynamic-${arch} clang_rt.asan-dynamic-${arch}-version-list)
+                # generates an order-only dependency in ninja.
+                RTAsan_dynamic_version_script_dummy
+                RTUbsan_cxx
+                ${ASAN_DYNAMIC_WEAK_INTERCEPTION}
+        CFLAGS ${ASAN_DYNAMIC_CFLAGS}
+        LINK_FLAGS ${ASAN_DYNAMIC_LINK_FLAGS}
+                  ${VERSION_SCRIPT_FLAG}
+        LINK_LIBS ${ASAN_DYNAMIC_LIBS}
+        DEFS ${ASAN_DYNAMIC_DEFINITIONS}
+        PARENT_TARGET asan)
+    endif()
 
     if (SANITIZER_USE_SYMBOLS AND NOT ${arch} STREQUAL "i386")
       add_sanitizer_rt_symbols(clang_rt.asan_cxx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants